这道题并不是真正的QTree,真正的QTree系列中QTree3为query on a tree again! <html> <body> <center><h2>1803: Spoj1487 Query on a tree III</h2><span class=green>Time Limit: </span>1 Sec <span class=green>Memory Limit: </span>64 MB<br><span class=green>Submit: </span>579 <span class=green>Solved: </span>260<br>[<a href='submitpage.php?id=1803'>Submit</a>][<a href='problemstatus.php?id=1803'>Status</a>][<a href='bbs.php?id=1803'>Discuss</a>]</center><h2>Description</h2><div class=content>You are given a node-labeled rooted tree with n nodes.
Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels.
</div><h2>Input</h2><div class=content>The first line contains one integer n (1 <= n <= 10^5). The next line contains n integers li (0 <= li <= 109) which denotes the label of the i-th node.
Each line of the following n - 1 lines contains two integers u, v. They denote there is an edge between node u and node v. Node 1 is the root of the tree.
The next line contains one integer m (1 <= m <= 10^4) which denotes the number of the queries. Each line of the next m contains two integers x, k. (k <= the total node number in the subtree of x)
</div><h2>Output</h2><div class=content> For each query (x, k), output the index of the node whose label is the k-th largest in the subtree of the node x. </div><h2>Sample Input</h2> <div class=content><span class=sampledata>5<br /> 1 3 5 2 7<br /> 1 2<br /> 2 3<br /> 1 4<br /> 3 5<br /> 4<br /> 2 3<br /> 4 1<br /> 3 2<br /> 3 2<br /> <br /> </span></div><h2>Sample Output</h2> <div class=content><span class=sampledata><br /> 5<br /> 4<br /> 5<br /> 5<br /> <br /> <br /> <br /> <br /> </span></div><h2>HINT</h2> <div class=content><p><br /> Amber的play with tree系列的题.... <br /> </p></div><h2>Source</h2> <div class=content><p><a href='problemset.php?search='></a></p></div><center>[<a href='submitpage.php?id=1803'>Submit</a>][<a href='problemstatus.php?id=1803'>Status</a>][<a href='bbs.php?id=1803'>Discuss</a>]</center><br>
</body> </html>
dfs序+主席树裸题